var MY_HOME_PAGE_COMMON = (function() {
	//自适应字体大小
	function fontChart(res) {
		//获取到屏幕的宽度
		var clientWidth =
			window.innerWidth ||
			document.documentElement.clientWidth ||
			document.body.clientWidth;
		if (!clientWidth) return; //报错拦截：
		var fontSize = 80 * (clientWidth / screen.width);
		return res * fontSize;
	}
	//全屏
	function fullScreen(){
		var el = document.documentElement;
		var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullscreen;
		if(typeof rfs != "undefined" && rfs) {
			rfs.call(el);
		};
		return;
	}
	//退出全屏
	function exitScreen(){
		if (document.exitFullscreen) {
			document.exitFullscreen();
		}
		else if (document.mozCancelFullScreen) {
			document.mozCancelFullScreen();
		}
		else if (document.webkitCancelFullScreen) {
			document.webkitCancelFullScreen();
		}
		else if (document.msExitFullscreen) {
			document.msExitFullscreen();
		}
		if(typeof cfs != "undefined" && cfs) {
			cfs.call(el);
		}
	}

	function jumpToInstitutionDetail(page ,institutionId, institutionName) {
		var screenState = '';
		//判断状态是否为全屏
		if ($("#full_scr").is(":hidden")) {
			screenState = 'fullScreen';
		} else {
			screenState = 'exitFullScreen';
		}

		if (page.length == 0 ||
			institutionId.length == 0 ||
			institutionName.length == 0) {
			return;
		}

		WeKnow.submit(
			'invs_institution_details.do',
			{
				screenState: screenState,
				pageId: page,
				institutionId: institutionId,
				institutionName: institutionName
			}
		);
	}

	//跳转
	function toWorkbench(title, status, date, otherData) {
		var today = date;// 0：今日  1：本周  2：近两个月  10：全部
		window.open("main.do?initPageTitle="+ title +"&today=" + today + "&status=" + status + "&otherData=" + otherData);
	}
	
	function externalJump(type) {
		switch (type) {
			case 'plesSystem':
				window.open("http://scq.139379.com:1168/new/");
				break;
			case 'cssSystem':
				window.open("http://59.202.42.163/admin/index_home")
				break;
			case 'administrativeManagement':
				window.open("http://hzjf.wsxg.net/")
				break;
			case 'examSystem':
				window.open("http://bg.zjwjw.gov.cn/admin-cms/login.html")
				break;
			default:
				break;
		}
	}

	return {
		fontChart:fontChart,
		fullScreen:fullScreen,
		exitScreen:exitScreen,
		jumpToInstitutionDetail:jumpToInstitutionDetail,
		toWorkbench:toWorkbench,
		externalJump:externalJump,
	}
})();

$(document).ready(function() {
	var screenState = $('#screenState').val();
	// 全屏
	$('.fullScreen-toggle').on('click',function(){
		var $that = $(this);
		// 全屏化7
		var target =$that.prop('id');
		if ( target =='full_scr' ) {
			$('nav').hide();

			MY_HOME_PAGE_COMMON.fullScreen();
			$('div.fullScreen').css('top',0);
			$('body').css('overflow-y',"hidden");
		} else {
			$('nav').show();
			MY_HOME_PAGE_COMMON.exitScreen();
			$('body').css('overflow-y',"scroll");
		}
		//全屏、退出全屏 图标切换
		$('.fullScreen-toggle').toggle();

	});
	//跳转过来前是全屏状态，默认全屏
	if ('fullScreen' == screenState) {
		$('nav').hide();
		MY_HOME_PAGE_COMMON.fullScreen();
		$('div.fullScreen').css('top',0);
		$('body').css('overflow-y',"hidden");
		//全屏、退出全屏 图标切换
		$('.fullScreen-toggle').toggle();
	} else {
		$('nav').show();
		MY_HOME_PAGE_COMMON.exitScreen();
		$('body').css('overflow-y',"scroll");
	}

	$(".tag-area .tag, .back, #institutionDetails,.warningSpan, div[class$='rect']").on('click',function () {
		var id = $(this).attr("id");
		var currentPage = $(this).val();
		var screenState = '';
		//判断状态是否为全屏
		if ($("#full_scr").is(":hidden")) {
			screenState = 'fullScreen';
		} else {
			screenState = 'exitFullScreen';
		}
		if (id == 'institutionReview') {
			WeKnow.submit(
				'invs_home_page.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'institutionAutonomy' || id == 'institutionAutonomyBack') {
			WeKnow.submit(
				'invs_institution_autonomy.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'industryAutonomy') {
			WeKnow.submit(
				'invs_industry_autonomy.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'governmentVision' || id == 'governmentVisionBack') {
			WeKnow.submit(
				'invs_government_vision.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'societyVision' || id == 'societyVisionBack') {
			WeKnow.submit(
				'invs_society_vision.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'comprehensiveApplication') {
			WeKnow.submit(
				'invs_comprehensive_application.do',
				{
					screenState: screenState
				}
			);
		}/*else if (id == 'feedback') {
			WeKnow.submit(
				'invs_feedback.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'warningHandle') {
			WeKnow.submit(
				'invs_warning_handle.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'decisionAnalysis') {
			WeKnow.submit(
				'invs_decision_analysis.do',
				{
					screenState: screenState
				}
			);
		}*/ else if (id == 'systemSetting') {
			WeKnow.submit(
				'invs_system_setting.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'lawEnforcement') {//政府监督 => 行政执法
			WeKnow.submit(
				'invs_law_enforcement.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'qrcodeSupervision') {//社会监督 => 二维码监督
			WeKnow.submit(
				'invs_qrcode_supervision.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'institutionDetails') {//机构详细信息
			var institutionId = $(this).data("institutionid");
			if (institutionId == undefined || institutionId == null || institutionId.length == 0) {
				return;
			}
			var institutionName = $(this).data("institutionname");
			if (institutionName == undefined || institutionName == null || institutionName.length == 0) {
				return;
			}
			WeKnow.submit(
				'invs_institution_details.do',
				{
					screenState: screenState,
					pageId: currentPage,
					institutionId: institutionId,
					institutionName: institutionName
				}
			);
		} else if (id == 'prescriptionSupervision') {//政府监管 => 行政执法 => 诊疗行为监管
			WeKnow.submit(
				'invs_prescription_supervision.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'accountSupervision') {//政府监管 => 行政执法 => 卫生消毒监管
			WeKnow.submit(
				'invs_account_supervision.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'medicalHis') {//机构自制 => 医疗His
			WeKnow.submit(
				'invs_medical_his.do',
				{
					screenState: screenState,
				}
			);
		} else if (id == 'autonomyExamination') {
			WeKnow.submit(
				'invs_autonomy_examination.do',
				{
					screenState: screenState
				})
		} else if (id == 'comprehensiveApplication') {//综合应用
			WeKnow.submit(
				'invs_comprehensive_application.do',
				{
					screenState: screenState
				}
			);
		} else if (id == 'logout') {//退出
			WeKnow.submit(
				'logout',
				{
					screenState: screenState
				}
			);
		} else if (id == 'plesSystem') {//政府监督 => 行政执法 => 专业执法监管
			//跨部门执法监管系统
			MY_HOME_PAGE_COMMON.externalJump(id);

		} else if (id == 'cssSystem') {//政府监督 => 行政执法 => 跨部门监管
			//专业执法监管系统(上城区卫键行政执法综合监管)
			MY_HOME_PAGE_COMMON.externalJump(id);

		} else if (id == 'administrativeManagement') {//政府监督 => 行政管理
			//杭州市不良执业行为积分系统
			MY_HOME_PAGE_COMMON.externalJump(id);

		} else if (id != undefined && id.indexOf('AutonomyExaminationSystem') != -1) {//机构自制 => 自律自查
			//浙江省医疗机构自查自律系统
			MY_HOME_PAGE_COMMON.externalJump('examSystem');

		} else if (id == 'invsHomePage') {//卫监 => 工作台
			window.open('main.do');

		} else if (id == 'statisticsStatement') {//综合应用 => 决策分析 => 决策分析
			window.open('invs_statistics_statement.do');

		} else if (id == 'warningDispose') {
			window.open('invs_warning_dispose.do');//综合应用 => 预警处置 => 预警处置

		} else if (id == 'warningDisposeOverall') {
			window.open('invs_warning_dispose.do?url=invs_autonomy_examination_overall.do&enforcementStatus=0');//预警处置 => 自律自查 => 全面自查

		} else if (id == 'warningDisposeDaily') {
			window.open('invs_warning_dispose.do?url=invs_autonomy_examination_daily.do&enforcementStatus=0');//预警处置 => 自律自查 => 日常自查

		} else if (id == 'warningDisposeEvaluation') {
			window.open('invs_warning_dispose.do?url=invs_wd_public_evaluation.do');//预警处置 => 社会监督 => 公众评价

		} else if (id == 'warningDisposeImport') {
			toWorkbench("invs_system_config.do","","","");

		} else{
			WeKnow.notifyMsg("该功能尚未开发，敬请期待。");
		}
	});

});

//跳转工作台
function toWorkbench(title, status, date, otherData) {
	var today = $('.date_fillter').eq(0).val();// 0：今日  1：本周  2：近两个月  10：全部
	if(date == "all"){
		today = "10";
	} else {
		today = date;
	}
	// WeKnow.submit("main.do?initPageTitle="+ title +"&today=" + today + "&status=" + status + "&otherData=" + otherData);
	window.open("main.do?initPageTitle="+ title +"&today=" + today + "&status=" + status + "&otherData=" + otherData);
}